import { computed } from "vue";
export function useVModel(props, propName, emit) {
  // 父子组件用computed拦截v-model 做中间代理
  return computed({
    get() {
      return new Proxy(props[propName], {
        get(target, key, receiver) {
          return Reflect.get(target, key, receiver);
        },
        set(target, key, val) {
          console.log("set", key, val);
          emit(`update:${propName}`, {
            ...target,
            [key]: val,
          });
          return true;
        },
      });
    },
    set(val) {
      console.log("set", val);
      emit(`update:${propName}`, val);
    },
  });
}
